<%--
  Created by IntelliJ IDEA.
  User: hc
  Date: 14-5-15
  Time: 下午16:10
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib uri="/struts-tags" prefix="s" %>
<html>
<head>
    <%@include file="../../common/include_list_head.jsp" %>
    <title></title>

    <script type="text/javascript">

        var idRoles = "";
        function CheckedInfo(obj) {

                var role = $("#Role_" + obj).val();
                if ($("#Role_" + obj).attr("checked")) {
                    idRoles = idRoles + "," + role;
            } else {
                if ("" != idRoles) {
                    var msg = "";
                    var roles = idRoles.split(",");
                    for (var j = 0; j < roles.length; j++) {
                        if (roles[j] != role) {
                            msg = "," + roles[j];
                        }
                    }

                    idRoles = msg;
                }
            }

            window.parent.document.getElementById("rolesId").value = idRoles;
//            alert(""+document.getElementById("appid").value);
            window.parent.document.getElementById("appid").value = document.getElementById("appid").value;
        }
    </script>
    <script type="text/javascript">

        $(document).ready(function () {
            window.parent.document.getElementById("rolesId").value = null;
            //菜单按层次向后两个空格
            $("td[id^='td_']").each(function (i) {
                var id_len_3 = $(this).attr("upid");
                var str = "";
                if (id_len_3 == '0') {
                        str = "&nbsp;&nbsp;&nbsp;";
                }else if(id_len_3 == '1'){
                        str = "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
                }else{
                    str="&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
                }
                $(this).html(str + $(this).html());
            });
//            //初始化选中 已选中的菜单
            //得到所有拥有门户权限的集合
//            var role = window.parent.document.getElementById("rolesId").value;
//            alert(""+role);
            var roles = window.parent.document.getElementById("roles").value;
            if (roles != null || roles != "") {
                var rolebuffer = document.getElementById("rolebuffer").value;
                var roles = roles.split(",");
                var rolebuffer = rolebuffer.split(",");
                for (var j = 0; j < rolebuffer.length; j++) {
                    for (var i = 0; i < roles.length; i++) {
                        if (rolebuffer[j] == roles[i]) {
                            $("#Role_" + roles[i]).attr("checked", "checked");
                            CheckedInfo(rolebuffer[j]);
                        }
                    }
                }
            }
        })
        ;
        //更新菜单信息
        function tochangeMenu(obj,wid,upid) {
            $(":checkbox[cupid='"+wid+"']").attr("checked",obj.checked);
        }
        function changeAll(obj) {
            window.parent.document.getElementById("menues").value = null;
            if (!obj.checked) {
                $("input[name^='selectNodeMenu']").each(function (i) { //二级菜单取消选中时,下级菜单全部取消选中
                    if (this.checked) { //该菜单的按钮已选中
                        $(this).attr("checked", ""); //选中菜单下的按钮后默认选中该菜单
                    }
                });
            } else { //选中二级菜单时,默认其下级菜单全部选中
                $("input[name='selectNodeMenu']").each(function (i) { //二级菜单取消选中时,下级菜单全部取消选中
                    $(this).attr("checked", "checked"); //选中菜单下的按钮后默认选中该菜单
                });
            }
        }
    </script>
</head>
<body style="height: 600px;">
<div style="height: 350px;">
    <s:if test="actionErrors.size()>0 || actionMessages.size()>0 || fieldErrors.size()>0">
        <div id="SystemErrorMessage">
            <s:actionerror/>
            <s:actionmessage/>
            <s:fielderror/>
        </div>
    </s:if>
    <s:hidden id="menues" name="menues"/>
    <div style="width:100%;min-height:60px;height: auto;">
        <s:iterator value="rolelist" status="status">
            <div style="margin-top: 20px;">
                <li style="float: left;width: 20%">
                <input type="checkbox" id="Role_<s:property value="roleid"/>" name="selectNode"
                       value="<s:property value="roleid"/>"
                       onclick="CheckedInfo('<s:property value="roleid"/>');"/>
                <a href="javascript:openEntity('<s:property value="roleid"/>')">
                    <font color="blue"><s:property value="rolename"/></font></a>
                <s:hidden name="appid" id="appid" value="%{appid}"/>
                <s:hidden name="rolebuffer" id="rolebuffer" value="%{rolebuffer}"/>
            </li>
            </div>
        </s:iterator>
    </div>

    <div style="height:390px;width:100%;" id="scrollContent" >
        <s:hidden id="roleids" value="%{roleids}"/>
        <table class="tableStyle" headFixMode="true" id="tab" style="font-size: 12px">
            <tr>
                <td align="left" colspan="3">
                    <s:checkbox id="menu_%{taccessAppRegid}" name="selectNodeMenuAll" fieldValue="%{taccessAppRegid}"
                                onclick="changeAll(this)"/>
                </td>
            </tr>
            <tr>
                <th align="center" width="20%">资源名称</th>
                <th align="center" width="15%">资源状态</th>
                <th align="center" width="15%">资源编码</th>

            </tr>

            <s:iterator value="lbxxlist" id="lm" status="i">
                <tr>

                    <td width="180" id="td_<s:property value='wid'/>" upid="<s:property value='upid'/>">

                        <s:checkbox id="menu_%{wid}" name="selectNodeMenu" fieldValue="%{wid}" cupid="%{upid}"
                                    onclick="tochangeMenu(this,'%{wid}','%{upid}')"/>
                        <label for="menu_<s:property value="%{wid}" />"><s:property value="name"/>
                            <span id="span_<s:property value='%{#i.index}'/>"></span></label>
                    </td>

                    <td align="center">
                        <s:if test="state==0">禁用</s:if>
                        <s:else>可用</s:else>
                    </td>

                    <td align="center">
                        <s:property value="des"/></td>
                    </td>
                </tr>
            </s:iterator>
        </table>
    </div>
</div>
</body>
</html>